﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Web.Script.Serialization;
using System.Text.RegularExpressions;
using System.Collections;
using System.Drawing;
using System.Drawing.Imaging;

/// <summary>
/// PageBase 的摘要说明
/// </summary>
public class PageBase : System.Web.UI.Page
{
    //public static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    public PageBase()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    #region 基本参数
    public static string systemlogo = GetConfig("LOGO");//系统标示
    /// <summary>
    /// 新GUID
    /// </summary>
    public static string NewGUID
    {
        get
        {
            //return DateTime.Now.ToString("yyyyMMddHHmmssffffff") + "_" + Convert.ToString(System.Guid.NewGuid());
            return DateTime.Now.ToString("yyyyMMddHHmmssfff") + systemlogo + Convert.ToString(System.Guid.NewGuid()).Replace("-", "").Substring(0, 15 - systemlogo.Length);
        }
    }
    //public Maticsoft.Model.JC_COMACCOUNT of_GetUser()
    //{

    //    Maticsoft.Model.JC_COMACCOUNT model;
    //    if (this.Session["USERINFO"] != null)
    //    {
    //        model = (Maticsoft.Model.JC_COMACCOUNT)this.Session["USERINFO"];
    //    }
    //    else
    //    {
    //        model = new Maticsoft.Model.JC_COMACCOUNT();
    //    }
    //    return model;
    //}
    /// <summary>
    /// 当前局
    /// </summary>
    public static string current_organizationid
    {
        get { return ConfigurationManager.AppSettings["JGID"]; }
    }
    public static string current_organizationno
    {
        get { return ConfigurationManager.AppSettings["JGNO"]; }
    }
    public static string WCFService
    {
        get { return ConfigurationManager.AppSettings["WCFService"]; }
    }
    public static string ConvertString(string exp1)
    {
        if (exp1 != "" && exp1 != null)
        {
            string exp2 = "";
            exp2 = exp1;
            exp2 = exp2.Replace(" ", "");
            exp2 = exp2.Replace("<", "<");
            exp2 = exp2.Replace(">", ">");
            exp2 = exp2.Replace("'", "''");
            exp2 = exp2.Replace("\r", "<br/>");
            exp2 = exp2.Replace("\n", "<br/>");
            exp2 = exp2.Replace("\0", " ");
            return exp2;
        }
        else
            return "";

    } 

    //判断类
    #endregion
    #region 公用基本方法类
    //public void Message(Page p, string str)
    //{
    //    p.ClientScript.RegisterStartupScript(p.GetType(), "", "top.messageError('错误','" + Maticsoft.Common.StringUtil.HtmlEncode(str) + "');", true);
    //}
    public void Message_ext(Page p, string js)
    {
        p.ClientScript.RegisterStartupScript(p.GetType(), "", js, true);
    }
    public static DataTable FilterdataTable(DataTable data, string condition)
    {
        if (data != null && data.Rows.Count > 0)
        {
            if (condition.Trim() == "")
            {
                return data;
            }
            else
            {
                DataTable newdt = new DataTable();
                newdt = data.Clone();
                DataRow[] dr = data.Select(condition);
                for (int i = 0; i < dr.Length; i++)
                {
                    newdt.ImportRow((DataRow)dr[i]);
                }
                return newdt;
            }
        }
        else
        {
            return null;
        }
    }
    //public void Message_ext1(Page p, int rvalue)
    //{
    //    try
    //    {
    //        if (rvalue == 0)
    //        {
    //            Message(p, "该登陆名已存在");
    //        }
    //        else
    //        {
    //            Message(p, "非常抱歉，操作失败，请稍候重试");
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Message(p, ex.Message);
    //    }
    //}

    //public void Message_ext1(Page p, int rvalue, string modelid)
    //{
    //    try
    //    {
    //        if (rvalue > 0)
    //        {
    //            Message_ext(Page, "top.closewin('" + modelid + "')");
    //        }
    //        else
    //        {
    //            Message(p, "非常抱歉，操作失败，请稍候重试");
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Message(p, ex.Message);
    //    }
    //}

    //public void Message_ext2(Page p, int rvalue, string modelid)
    //{
    //    try
    //    {
    //        if (rvalue > 0)
    //        {
    //            Message_ext(Page, "top.operate(true," + rvalue + ",'" + modelid + "');");
    //        }
    //        else
    //        {
    //            Message(p, "非常抱歉，操作失败，请稍候重试");
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Message(p, ex.Message);
    //    }
    //}
    //public void Message_ext1(Page p, int rvalue, int refresh)
    //{
    //    try
    //    {
    //        if (rvalue > 0)
    //        {
    //            Message_ext(Page, "top.operate(" + rvalue + "," + refresh + ");");
    //        }
    //        else
    //        {
    //            Message(p, "非常抱歉，操作失败，请稍候重试");
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Message(p, ex.Message);
    //    }
    //}
    //public void Message_ext1(Page p, int rvalue, int isclosewin, string winid, string fwinid)
    //{
    //    try
    //    {
    //        if (rvalue > 0)
    //        {
    //            Message_ext(Page, "parent.operate(true," + isclosewin + ",null,null,'" + winid + "','" + fwinid + "');");
    //        }
    //        else
    //        {
    //            Message(p, "非常抱歉，操作失败，请稍候重试");
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Message(p, ex.Message);
    //    }
    //}
    //public void Message_ext1(Page p, int rvalue, int isclosewin, string winid, string fwinid, bool isrefresh)
    //{
    //    string _isrefresh = "true";
    //    if (!isrefresh)
    //    {
    //        _isrefresh = "false";
    //    }
    //    try
    //    {
    //        if (rvalue > 0)
    //        {
    //            Message_ext(Page, "parent.operate(true," + isclosewin + ",null,null," + winid + "," + fwinid + "," + _isrefresh + ");");
    //        }
    //        else
    //        {
    //            Message(p, "非常抱歉，操作失败，请稍候重试");
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Message(p, ex.Message);
    //    }
    //}
    //public void Message_ext2(Page p, int rvalue, bool isclosewin, bool isrefresh, string winid, string fwinid)
    //{
    //    string str = "parent.operate1({";
    //    str += "value:" + rvalue;
    //    str += isclosewin ? ",isclosewin:true" : ",isclosewin:false";
    //    str += isrefresh ? ",isrefresh:true" : ",isrefresh:false";
    //    str += winid != "" ? ",winid:'" + winid + "'" : "";
    //    str += fwinid != "" ? ",fwinid:'" + fwinid + "'" : "";
    //    str += "});";
    //    try
    //    {
    //        if (rvalue > 0)
    //        {
    //            Message_ext(Page, str);
    //        }
    //        else
    //        {
    //            Message(p, "非常抱歉，操作失败，请稍候重试");
    //        }
    //    }
    //    catch (Exception ex)
    //    {
    //        Message(p, ex.Message);
    //    }
    //}
    /// <summary>
    /// 检查当前用户权限
    /// </summary>
    //public bool checkuser()
    //{
    //    if (this.of_GetUser() != null)
    //    {//检查用户是否登录
    //        //string root = ConfigurationManager.AppSettings["root"].ToString();
    //        //string msg = "var url=location.href.replace('#','').replace('##','').replace('###','').replace(location.search,'').replace(location.pathname,'');";
    //        //msg += "url+='" + root + "'+'/loginout.aspx';";
    //        //msg += "top.location.href=url;";
    //        //Page.ClientScript.RegisterStartupScript(this.GetType(), "", msg, true);
    //        Response.Redirect("~/loginout.aspx");
    //        return false;
    //        //其他权限待扩展
    //    }
    //    else
    //    {
    //        return true;
    //    }
    //}
    public static string GetConfig(string id)
    {
        try
        {
            return ConfigurationManager.AppSettings[id].ToString();
        }
        catch (Exception)
        {
            return "";
        }
    }
    /// <summary>
    /// 文件服务地址
    /// </summary>
    /// <returns></returns>
    public static string GetFilePath()
    {
        string FilePath = GetConfig("FileService") + GetConfig("FilesPath");
        return FilePath;
    }
    public string stringCut(string str, int len)
    {
        try
        {
            if (str.Length < len)
            {
                return str;
            }
            else
            {
                return str.Substring(0, len) + "...";
            }
        }
        catch (Exception ex)
        {
            return "";
        }
    }
    public static int ext_int(object o)
    {
        int r;
        if (int.TryParse(o + "", out r))
        {
            return r;
        }
        else
        {
            return 0;
        }
    }
    public static decimal? ext_decimal(object o)
    {
        decimal r;
        if (decimal.TryParse(o + "", out r))
        {
            return r;
        }
        else
        {
            return null;
        }
    }
    public static decimal ext_decimal1(object o)
    {
        decimal r;
        if (decimal.TryParse(o + "", out r))
        {
            return r;
        }
        else
        {
            return 0M;
        }
    }
    /// <summary>
    /// 精度
    /// </summary>
    /// <param name="o"></param>
    /// <param name="len"></param>
    /// <returns></returns>
    public static decimal ext_decimalRound(object o, int len)
    {
        return decimal.Round(Convert.ToDecimal(ext_decimal(o, 0)), len);
    }
    /// <summary>
    /// 初始值
    /// </summary>
    /// <param name="o"></param>
    /// <param name="r"></param>
    /// <returns></returns>
    public static decimal? ext_decimal(object o, decimal _r)
    {
        decimal r;
        if (decimal.TryParse(o + "", out r))
        {
            return r;
        }
        else
        {
            return _r;
        }
    }
    public static string ext_string(object o)
    {
        if (o != null && o != "")
        {
            try
            {
                if (o.ToString().Trim() == "undefined")
                {
                    return "";
                }
                else
                {
                    return o.ToString().Trim();
                }
            }
            catch (Exception)
            {
                return "";
            }
        }
        else
        {
            return "";
        }
    }
    public static DateTime? ext_date(object o)
    {
        if (o != null && o != "")
        {
            try
            {
                string rvalue = o.ToString();
                if (rvalue.IndexOf("reserved-") >= 0)
                {
                    return DateTime.FromOADate(double.Parse(rvalue.Replace("reserved-", "").Replace("x1F", "")));
                }
                else
                {
                    return Convert.ToDateTime(o);
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }
    public static string ext_date1(object o)
    {
        if (o != null && o != "")
        {
            try
            {
                return Convert.ToDateTime(o).ToString("yyyy-MM-dd HH:mm");
            }
            catch (Exception)
            {
                return null;
            }
        }
        else
        {
            return "";
        }
    }
    public static string ext_date1(object o, string format)
    {
        if (o != null && o != "")
        {
            try
            {
                return Convert.ToDateTime(o).ToString(format);
            }
            catch (Exception)
            {
                return null;
            }
        }
        else
        {
            return "";
        }
    }
    /// <summary>
    /// 日志（写入文件）
    /// </summary>
    /// <param name="_str"></param>
    //public void log(string _str)
    //{
    //    string directory = "~/log/" + DateTime.Now.ToString("yyyy-MM") + "/";
    //    string filepath = directory + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
    //    string logFile = Server.MapPath(filepath);
    //    string userinfo = "操作人:" + this.of_GetUser().USERID + "(" + this.of_GetUser().ID + ")";
    //    StreamWriter sw = null;
    //    try
    //    {
    //        if (!System.IO.Directory.Exists(Server.MapPath(directory)))
    //        {
    //            System.IO.Directory.CreateDirectory(Server.MapPath(directory));
    //        }
    //        if (File.Exists(logFile))
    //        {
    //            sw = File.AppendText(logFile);
    //        }
    //        else
    //        {
    //            sw = File.CreateText(logFile);
    //        }
    //        sw.WriteLine(System.DateTime.Now.ToString() + "   IP:" + Request.UserHostAddress);
    //        sw.WriteLine(userinfo);
    //        sw.WriteLine("出错信息：" + _str);
    //        sw.WriteLine("---------------------------------------------------------------------");
    //        sw.Flush();
    //        sw.Close();
    //        sw.Dispose();
    //        sw = null;
    //    }
    //    catch (Exception)
    //    {
    //    }
    //}
    /// <summary>
    /// 日志（写入数据库）
    /// </summary>
    /// <param name="model"></param>
    //public void logoracle(Maticsoft.Model.BASE_LOG model)
    //{
    //    Maticsoft.BLL.BASE_LOG bll = new Maticsoft.BLL.BASE_LOG();
    //    try
    //    {
    //        model.ID = NewGUID;
    //        model.USERID = this.of_GetUser().ID;
    //        model.USERIP = HttpContext.Current.Request.UserHostAddress;
    //        bll.Add(model);
    //    }
    //    catch (Exception ex)
    //    {
    //        log(ex.Message);
    //    }
    //}
    public static string DateTimeStr(string str)
    {
        try
        {
            return Convert.ToDateTime(str).ToString("yyyy-MM-dd");
        }
        catch
        {
            return str;
        }
    }
    public static string ToJson(object o)
    {
        //序列化对象为json数据，很重要！
        JavaScriptSerializer j = new JavaScriptSerializer();
        return j.Serialize(o);
    }
    public static string easyui_json(DataSet ds, string data)
    {
        int total = 0;//总条数
        if (ds.Tables.Count > 1)
        {
            total = ext_int(ds.Tables[0].Rows[0][0].ToString());
            return "{\"total\":" + total + ",\"rows\":" + data + "}";
        }
        else
        {
            return data;
        }
    }
    public static string easyui_json(int count, string data)
    {
        return "{\"total\":" + count + ",\"rows\":" + data + "}";
    }
    public static string datatable_json(int draw, int count, string data)
    {
        return "{\"draw\":" + draw + ",\"recordsTotal\":" + count + ",\"recordsFiltered\":" + count + ",\"data\":" + data + "}";
    }
    public static string jqgrid_json(int page, int rows, int _records, string data)
    {
        int total = 0;//分页数
        int total1 = 0;//余数
        int records = _records;//总条数
        decimal? sbcounts = 0m;//设备总数量
        if (rows != 0)
        {
            total = records / rows;
            total1 = records % rows;
        }
        if (total1 > 0)
        {
            total += 1;
        }
        return "{\"page\":" + page + ",\"records\":" + records + ",\"total\":" + total + ",\"userdata\":{\"sbcounts\":\"" + sbcounts + "\"},\"rows\":" + data + "}";
    }
    public static string jqgrid_jsonToHj(int page, int rows, DataSet ds, string data)
    {
        int total = 0;//分页数
        int total1 = 0;//余数
        int records = 0;//总条数
        decimal? sumyf = 0;
        decimal? sumdff = 0;
        decimal? sbcounts = 0m;//设备总数量
        if (ds.Tables.Count > 1)
        {
            records = ext_int(ds.Tables[0].Rows[0][0].ToString());
            if (ds.Tables[0].Columns.Count > 1) { sbcounts = ext_decimal(ds.Tables[0].Rows[0][1].ToString()); }
            if (ds.Tables[2].Rows.Count > 0)
            {
                sumyf = ext_decimal(ds.Tables[2].Rows[0]["yf"].ToString());
                sumdff = ext_decimal(ds.Tables[2].Rows[0]["dff"].ToString());
            }
        }
        else
        {
            records = ds.Tables[0].Rows.Count;
        }
        if (rows != 0)
        {
            total = records / rows;
            total1 = records % rows;
        }
        if (total1 > 0)
        {
            total += 1;
        }
        return "{\"page\":" + page + ",\"totalSum\":" + sumyf + ",\"totalSumDFF\":" + sumdff + ",\"records\":" + records + ",\"total\":" + total + ",\"userdata\":{\"sbcounts\":\"" + sbcounts + "\"},\"rows\":" + data + "}";
    }
    public static string jqgrid_json(int page, int rows, DataSet ds, string data)
    {
        int total = 0;//分页数
        int total1 = 0;//余数
        int records = 0;//总条数
        decimal? sbcounts = 0m;//设备总数量
        if (ds.Tables.Count > 1)
        {
            records = ext_int(ds.Tables[0].Rows[0][0].ToString());
            if (ds.Tables[0].Columns.Count > 1) { sbcounts = ext_decimal(ds.Tables[0].Rows[0][1].ToString()); }
        }
        else
        {
            records = ds.Tables[0].Rows.Count;
        }
        if (rows != 0)
        {
            total = records / rows;
            total1 = records % rows;
        }
        if (total1 > 0)
        {
            total += 1;
        }
        return "{\"page\":" + page + ",\"records\":" + records + ",\"total\":" + total + ",\"userdata\":{\"sbcounts\":\"" + sbcounts + "\"},\"rows\":" + data + "}";
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="page"></param>
    /// <param name="rows"></param>
    /// <param name="ds"></param>
    /// <param name="data">数据</param>
    /// <param name="userdata">自定义数据</param>
    /// <returns></returns>
    public static string jqgrid_json(int page, int rows, DataSet ds, string data, string userdata)
    {
        int total = 0;//分页数
        int total1 = 0;//余数
        int records = 0;//总条数
        decimal? sbcounts = 0m;//设备总数量
        if (ds.Tables.Count > 1)
        {
            records = ext_int(ds.Tables[0].Rows[0][0].ToString());
            if (ds.Tables[0].Columns.Count > 1) { sbcounts = ext_decimal(ds.Tables[0].Rows[0][1].ToString()); }
        }
        else
        {
            records = ds.Tables[0].Rows.Count;
        }
        if (rows != 0)
        {
            total = records / rows;
            total1 = records % rows;
        }
        if (total1 > 0)
        {
            total += 1;
        }
        return "{\"page\":" + page + ",\"records\":" + records + ",\"total\":" + total + ",\"userdata\":" + userdata + ",\"rows\":" + data + "}";
    }
    public static string jqgrid_treejson(int page, int rows, DataSet ds, string data)
    {
        int total = 0;//分页数
        int total1 = 0;//余数
        if (rows != 0)
        {
            total = ext_int(ds.Tables[0].Rows.Count) / rows;
            total1 = ext_int(ds.Tables[0].Rows.Count) % rows;
        }
        if (total1 > 0)
        {
            total += 1;
        }
        return "{\"page\":" + page + ",\"records\":" + ext_int(ds.Tables[0].Rows.Count) + ",\"total\":" + total + ",\"rows\":[" + data + "]}";
    }
    /// <summary>
    /// 得到当前机构下的子机构
    /// </summary>
    /// <param name="str"></param>
    /// <param name="ds"></param>
    /// <param name="fid"></param>
    public void getsun(StringBuilder sb, DataSet ds, string fid)
    {
        DataRow[] dr = ds.Tables[0].Select(" ID ='" + fid + "'");
        if (dr.Length > 0)
        {
            sb.Append("'" + dr[0]["ID"].ToString() + "',");
        }
        dr = ds.Tables[0].Select(" AFFILIATIONID ='" + fid + "'");
        for (int i = 0; i < dr.Length; i++)
        {
            sb.Append("'" + dr[i]["ID"].ToString() + "',");
            DataRow[] dr1 = ds.Tables[0].Select(" AFFILIATIONID ='" + dr[i]["ID"].ToString() + "'");
            if (dr1.Length > 0)
            {
                getsun(sb, ds, dr[i]["ID"].ToString());
            }
        }
    }
    //public void getsunstr(StringBuilder sb, string fid)
    //{
    //    Maticsoft.BLL.JG_ORGANIZATIONG bll = new Maticsoft.BLL.JG_ORGANIZATIONG();
    //    DataSet ds = bll.GetList("");
    //    getsun(sb, ds, fid);
    //}
    public string getconfig(string value)
    {
        return ext_string(ConfigurationManager.AppSettings[value].ToString());
    }
    /// <summary>
    /// DropDownList数据字典
    /// </summary>
    /// <param name="dd"></param>
    /// <param name="id"></param>
    /// <param name="isall"></param>
    //public void dictionary(DropDownList dd, string id, bool isall)
    //{
    //    Maticsoft.BLL.JC_DICTIONARY bll = new Maticsoft.BLL.JC_DICTIONARY();
    //    DataSet ds = bll.GetList(" F_GUID='" + id + "' and ISACTIVE=1 order by SQU");
    //    dd.DataSource = ds.Tables[0];
    //    dd.DataTextField = "DICTIONARY_NAME";
    //    dd.DataValueField = "GUID";
    //    dd.DataBind();
    //    if (isall)
    //    {
    //        dd.Items.Insert(0, new ListItem("-全部-", ""));
    //    }
    //    else
    //    {
    //        dd.Items.Insert(0, new ListItem("--请选择--", ""));
    //    }
    //}
    /// <summary>
    /// DropDownList数据字典
    /// </summary>
    /// <param name="dd"></param>
    /// <param name="id"></param>
    /// <param name="isall"></param>
    //public void dictionary(DropDownList dd, string id, int showtype)
    //{
    //    Maticsoft.BLL.JC_DICTIONARY bll = new Maticsoft.BLL.JC_DICTIONARY();
    //    DataSet ds = bll.GetList(" F_GUID='" + id + "' and ISACTIVE=1 order by SQU");
    //    dd.DataSource = ds.Tables[0];
    //    dd.DataTextField = "DICTIONARY_NAME";
    //    dd.DataValueField = "GUID";
    //    dd.DataBind();
    //    switch (showtype)
    //    {
    //        case 1:
    //            dd.Items.Insert(0, new ListItem("全部", ""));
    //            break;
    //        case 2:
    //            dd.Items.Insert(0, new ListItem("--请选择--", ""));
    //            break;
    //        case 3:
    //            dd.Items.Insert(0, new ListItem("--未选择--", ""));
    //            break;
    //        case 4:
    //            dd.Items.Insert(0, new ListItem("  ", ""));
    //            break;

    //    }
    //}
    #endregion

    #region 其他方法
    //公里标格式转化
    public static string tokm(string o)
    {
        //公里标格式化 k1000+0001
        string rvalue = "";
        try
        {
            var point = o.ToString().IndexOf('.');
            if (point > 0)
            {
                float a = float.Parse("0." + o.ToString().Substring(point + 1)) * 1000;
                rvalue = 'K' + o.ToString().Substring(0, point) + '+' + a.ToString().Substring(0, a.ToString().Length);
            }
            else
            {
                if (o == "" || o == null)
                {
                    rvalue = "";
                }
                else
                {
                    rvalue = 'K' + o.ToString();
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return rvalue;
    }
    /// <summary>
    ///公里标格式转化
    /// </summary>
    /// <param name="o"> K123+123.236</param>
    /// <returns>123.123123</returns>
    public static string getKM(string o)
    {
        decimal r = 0;
        if (o != "" && o.Replace('K', 'k').Contains("k"))
        {
            o = o.Substring(1);
        }

        if (o.IndexOf('+') > 0)
        {
            r = ext_decimalRound(o.Substring(0, o.IndexOf('+')) + "." + o.Substring(o.LastIndexOf('+') + 1).Replace(".", ""), 8 + o.Length - 1);
        }
        else
        {
            r = ext_decimalRound(o, 8 + o.Length);
        }
        return r.ToString();
    }
    /// <summary>
    /// 将字符串替换为's1','s2'.....
    /// nan -20120808
    /// </summary>
    /// <param name="str"></param>
    /// <param name="splitstr">分隔符</param>
    /// <returns></returns>
    public static string tosplit(string str, char splitstr)
    {
        string rvalue = "";
        if (str == null || str.Trim() == "") { return "''"; }
        string[] strs = str.Split(splitstr);
        for (int i = 0; i < strs.Length; i++)
        {
            if (strs[i] != "")
            {
                rvalue += "'" + strs[i] + "'";
                if (i < strs.Length - 1)
                {
                    rvalue += ",";
                }
            }
        }
        return rvalue;
    }
    /// <summary>
    /// 将字符串替换为's1','s2'.....
    /// nan -20120808
    /// </summary>
    /// <param name="str"></param>
    /// <param name="splitstr">分隔符</param>
    /// <returns></returns>
    public static string tosplit1(string str, char splitstr)
    {
        string rvalue = "";
        if (str.Trim() == "") { return "''"; }

        string[] strs = str.Split(splitstr);
        for (int i = 0; i < strs.Length - 1; i++)
        {
            if (strs[i] != "")
            {
                rvalue += "'" + strs[i] + "'";
                if (i < strs.Length - 2)
                {
                    rvalue += ",";
                }
            }
        }
        return rvalue;
    }
    /// <summary>
    /// 建立其他数据库link
    /// </summary>
    /// <param name="linkname"></param>
    /// <returns></returns>
    //public static Maticsoft.Model.BASE_DB DB_model(string linkname)
    //{
    //    try
    //    {
    //        Maticsoft.Model.BASE_DB DBmodel = new Maticsoft.Model.BASE_DB(Maticsoft.DBUtility.PubConstant.GetConnectionString(linkname));
    //        string sql = "";
    //        DataSet ds = new DataSet();
    //        ArrayList a = new ArrayList();
    //        sql = "select * from dba_db_links where db_link like'" + linkname + "%'";//是否创建目标数据库link
    //        ds = Maticsoft.DBUtility.DbHelperMySQL.Query(sql);
    //        if (ds.Tables[0].Rows.Count > 0)
    //        {//创建目标数据库link
    //            sql = "DROP PUBLIC DATABASE link " + ds.Tables[0].Rows[0]["db_link"].ToString();
    //            a.Add(sql);
    //        }
    //        sql = "create public database link " + linkname + " connect to " + DBmodel.UserID + " identified by \"" + DBmodel.Password + "\"   using '" + DBmodel.DataSource + "'";
    //        a.Add(sql);
    //        Maticsoft.DBUtility.DbHelperMySQL.ExecuteSqlTran2(a);
    //        return DBmodel;
    //    }
    //    catch (Exception) { return null; }
    //}
    /// <summary>
    /// 根据JGID得到dblink
    /// </summary>
    /// <param name="jgid"></param>
    /// <returns></returns>
    //public static string getDBLink(string jgid)
    //{
    //    object objModel = DataCache.GetCache("DB");
    //    string dblink = "";
    //    DataSet ds = new DataSet();
    //    if (objModel == null)
    //    {
    //        ds = Maticsoft.DBUtility.DbHelperMySQL.Query("select id,ORGANIZATIONGNAME,ip,db from JG_ORGANIZATIONG where db is not null");
    //        DataCache.SetCache("DB", ds, DateTime.Now.AddMinutes(180), TimeSpan.Zero);
    //    }
    //    else
    //    {
    //        ds = (DataSet)objModel;
    //    }
    //    DataRow[] drs = ds.Tables[0].Select("id='" + jgid + "'");
    //    if (drs.Length > 0) { dblink = drs[0]["DB"].ToString(); }
    //    return dblink;
    //}
    #endregion
    #region 公用方法sqlwhere
    /// <summary>
    /// 加入维管段限制条件
    /// </summary>
    /// <param name="filed"></param>
    /// <returns></returns>
    //public static string sqlwhere_wgjg(string filed)
    //{
    //    PageBase p = new PageBase();
    //    string sqlwhere = "";
    //    sqlwhere += p.of_GetUser().ORGANIZATIONGNAME2WJGIDS != "" ? " and " + filed + " in(select * from table(select  fn_split(t1.wgjgids,'|') from jg_organizationg t1 where t1.id='" + p.of_GetUser().ORGANIZATIONGID2 + "'))" : "";
    //    return sqlwhere;
    //}
    #endregion

   
}
